//
//  LGOrderConfirmController.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/1/14.
//

#import "LGOrderConfirmController.h"
#import "LGConfirmTableController.h"
#import "LGConfirmTableController2.h"
#import "LGDeviceManageTableController.h"
@interface LGOrderConfirmController ()<LGConfirmTableDelegate>
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)LGConfirmTableController *waitVC;
/**   */
@property (nonatomic , strong)LGConfirmTableController2 *alreadyVC;
/**   */
@property (nonatomic , strong)NSMutableArray *controllerArray;
/**   */
@property (nonatomic , copy)NSString *waitTitle;
/**   */
@property (nonatomic , copy)NSString *alreadyTitle;

@end

@implementation LGOrderConfirmController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.waitTitle = @"待认领";
    self.alreadyTitle = @"已认领";
    [self commonInit];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/order/pagedList" parameters:@{@"data_type":@"2",@"order_type":@"10",@"client":@"APP"} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            //总数
            NSInteger total = [LGNSString(returnData[@"total"]) integerValue];
            [self totalNumberChanged:total type:@"2"];
        }
    }error:^(NSError *error) {
        
    }];
}

-(void)totalNumberChanged:(NSInteger)number type:(NSString *)type{
    if ([type isEqualToString:@"1"]) {
        self.waitTitle = @"待认领";
    }else{
        self.alreadyTitle = [NSString stringWithFormat:@"已认领(%ld)",number];
        [self.menuView updateTitle:self.alreadyTitle atIndex:1 andWidth:NO];
    }
}



-(void)needRefressData{
    [self.alreadyVC requestData];
}

#pragma mark
#pragma mark ====> WMPageControllerDelegate
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.controllerArray.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    NSString *title = (index == 0)?self.waitTitle:self.alreadyTitle;
    return title;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    return self.controllerArray[index];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    return Screen_W/2.0;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, 0, Screen_W, viewPix(30));
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    return CGRectMake(0, viewPix(30), Screen_W, Screen_H-topBarHeight-viewPix(30));
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSLog(@">>>>>willEnterView>>>%@",viewController.title);
}


- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSLog(@">>>>>didEnterView>>>%@",viewController.title);
}



#pragma mark
#pragma mark ====> 创建控件
-(void)commonInit{
    self.title = @"订单认领";
    self.view.backgroundColor = [UIColor colorWithString:@"#E5F1FF"];
    [self addChildViewController:self.waitVC];
    [self addChildViewController:self.alreadyVC];
    [self.controllerArray addObject:self.waitVC];
    [self.controllerArray addObject:self.alreadyVC];
        
    self.titleColorNormal = [UIColor colorWithString:@"#666666"];
    self.titleColorSelected = [UIColor colorWithString:@"#4C87FD"];
    self.progressColor = [UIColor colorWithString:@"#3291FF"];
    self.menuViewStyle=WMMenuViewStyleLine;
    self.titleFontName = @"STHeitiTC-Medium";
    self.titleSizeSelected = 16;
    self.titleSizeNormal = 14;
    self.progressWidth = viewPix(13);
    self.progressHeight = 4;
    self.progressViewBottomSpace = 0;
    self.progressViewCornerRadius = 2;
    self.menuView.backgroundColor = [UIColor clearColor];
    self.scrollView.backgroundColor = [UIColor clearColor];
    [self reloadData];
}

-(CAGradientLayer *)gradientLayer{
    if(!_gradientLayer){
        _gradientLayer = [CAGradientLayer layer];
        _gradientLayer.frame = CGRectMake(0, 0, Screen_W, viewPix(167));
        _gradientLayer.startPoint = CGPointMake(0.5, 0);
        _gradientLayer.endPoint = CGPointMake(0.5, 1.03);
        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E5F1FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F9FE"].CGColor, (__bridge id)[UIColor colorWithString:@"#F3F7F8"].CGColor];
        _gradientLayer.locations = @[@(0), @(0.4f), @(1.0f)];
    }
    return _gradientLayer;
}

-(NSMutableArray *)controllerArray{
    if(!_controllerArray){
        _controllerArray = [NSMutableArray array];
    }
    return _controllerArray;
}

-(LGConfirmTableController *)waitVC{
    if(!_waitVC){
        _waitVC = [[LGConfirmTableController alloc]init];
        _waitVC.type = @"1";
        _waitVC.delegate = self;
    }
    return _waitVC;
}

-(LGConfirmTableController2 *)alreadyVC{
    if(!_alreadyVC){
        _alreadyVC = [[LGConfirmTableController2 alloc]init];
        _alreadyVC.type = @"2";
        _alreadyVC.delegate = self;
    }
    return _alreadyVC;
}
    
    
@end
